package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.FormGroupFieldAddDTO;
import org.jsola.hr.dto.FormGroupFieldUpdateDTO;
import org.jsola.hr.entity.FormGroupFieldDO;
import org.jsola.hr.query.FormGroupFieldQuery;
import org.jsola.hr.service.IFormGroupFieldService;
import org.jsola.hr.vo.FormGroupFieldVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 表单字段
 *
 * @author zhr
 */
@Component
public class FormGroupFieldTestHelper extends BaseTestHelper {
    
    @Autowired
    private IFormGroupFieldService formGroupFieldService;

    /**
     * 生成add测试数据
     * @return FormGroupFieldAddDTO
     */
    public FormGroupFieldAddDTO getFormGroupFieldAddDTO(){
        FormGroupFieldAddDTO formGroupFieldAddDTO = new FormGroupFieldAddDTO();
        formGroupFieldAddDTO.setModuleName(getRandomValue("varchar",50));
        formGroupFieldAddDTO.setModuleCode(getRandomValue("varchar",30));
        formGroupFieldAddDTO.setFieldName(getRandomValue("varchar",32));
        formGroupFieldAddDTO.setFieldCode(getRandomValue("varchar",32));
        formGroupFieldAddDTO.setFieldSource(SafeKit.getInteger(getRandomValue("int",2)));
        formGroupFieldAddDTO.setFieldType(SafeKit.getInteger(getRandomValue("int",2)));
        formGroupFieldAddDTO.setOptions(getRandomValue("text",2147483647));
        formGroupFieldAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        formGroupFieldAddDTO.setIsEdit(SafeKit.getInteger(getRandomValue("int",2)));
        formGroupFieldAddDTO.setIsNecessary(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        formGroupFieldAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        formGroupFieldAddDTO.setSubjectType(getRandomValue("varchar",100));
        formGroupFieldAddDTO.setSubjectId(getRandomValue("varchar",100));
        return formGroupFieldAddDTO;
    }


    /**
     * 生成update测试数据
     * @return FormGroupFieldUpdateDTO
     */
    public FormGroupFieldUpdateDTO getFormGroupFieldUpdateDTO(FormGroupFieldVO formGroupFieldVO){
        return formGroupFieldService.selectDOById(formGroupFieldVO.getId(), SITE_ID).to(FormGroupFieldUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return FormGroupFieldQuery
     */
    public FormGroupFieldQuery getFormGroupFieldQuery() {
        FormGroupFieldQuery formGroupFieldQuery = new FormGroupFieldQuery();
        List<FormGroupFieldDO> formGroupFieldDOList = formGroupFieldService.list(new FormGroupFieldDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(formGroupFieldDOList)) {
            FormGroupFieldDO formGroupFieldDO = formGroupFieldDOList.get(0);
            formGroupFieldQuery = formGroupFieldDO.to(FormGroupFieldQuery.class);
        }
        return formGroupFieldQuery;
    }

    /**
     * 保存示例
     * @return FormGroupFieldVO
     */
    public FormGroupFieldVO saveFormGroupFieldExample(){
        FormGroupFieldAddDTO addDTO = this.getFormGroupFieldAddDTO();
        FormGroupFieldVO formGroupFieldVO = formGroupFieldService.save(addDTO,buildTokenUser());
        return formGroupFieldVO;
    }


}

